<!doctype html>
<html>
<head>
    <!--Setting-->
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta name="apple-mobile-web-app-capable"  content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no,email=no">
    
    
    <!--Simple SEO-->


<meta name="robots" content=all />
<meta name="google" content=all />
<meta name="googlebot" content=all />
<meta name="verify" content=all />
    <!--Title-->

<title>ansible基础 | MIAbon&#39;s blog</title>

<link rel="alternate" href="/atom.xml" title="MIAbon&#39;s blog" type="application/atom+xml">


<link rel="icon" href="/favicon.ico">

    
<link rel="stylesheet" href="/css/base.css">
<link rel="stylesheet" href="/css/pages/post.css">
<link rel="stylesheet" href="//cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="/css/thirdParty/highlight/github.css">
<link rel="stylesheet" href="/.css">

    <!--script-->


<script src="http://cdn1.lncld.net/static/js/3.2.1/av-min.js"></script>
<script>
  var appId = "i7AHmC7NPbPtgS3YxT67dRIc-9Nh9j0Va";
  var appKey = "g6TKbY8O4TsCDMcemoC3STvQ";
  var region = "";
  AV.init({
    appId: appId,
    appKey: appKey,
    region: region
  });
</script>


<script async src="//dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>

<!--<script src="https://imsun.github.io/gitment/dist/gitment.browser.js"></script>-->


    
    
</head>

<body id="normal">
<!--[if lte IE 8]>
<style>
    html{ font-size: 1em }
</style>
<![endif]-->
<!--[if lte IE 9]>
<style>
    header{ top: 71px; position: absolute!important;}
    #container{padding-top: 151px!important;}
</style>
<div style="position:fixed;z-index:9999;left:0;top:0;width:100%;height:70px;background-color:#e0e0e0;color:#396CA5;border-bottom:1px solid #cecece;text-align:center;line-height:70px;white-space: nowrap;overflow: hidden;text-overflow: ellipsis">你使用的浏览器版本过低，为了你更好的阅读体验，请更新浏览器的版本或者使用其他现代浏览器，比如Chrome、Firefox、Safari等。</div>
<![endif]-->

<div id="wrap">
    <header  style="position: absolute;" >
    <div id="site-meta">
        <a href="/" id="logo">
            <h1 class="title">MIAbon&#39;s blog</h1>
        </a>
        
    </div>
    <ul id="nav">
        
            <li><a href="/"><i class="fa fa-home"></i>首页</a></li>
        
            <li><a href="/atom.xml"><i class="fa fa-rss"></i>RSS</a></li>
        
        <li id="search"><a href="javascript:void(0)"><i class="fa fa-search"></i>搜索</a></li>
    </ul>
</header>

    <div id="container">
        
<ul id="sidebar">
    
    
    
    
<li class="widget widget-normal category">
    <h3 class="fa fa-th widget-title">分类</h3>
    <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/categories/ELK/"><i class="fa" aria-hidden="true">ELK</i></a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/Lvs/"><i class="fa" aria-hidden="true">Lvs</i></a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/admin/"><i class="fa" aria-hidden="true">admin</i></a><span class="category-list-count">5</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/ansible/"><i class="fa" aria-hidden="true">ansible</i></a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/aws/"><i class="fa" aria-hidden="true">aws</i></a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/docker/"><i class="fa" aria-hidden="true">docker</i></a><span class="category-list-count">7</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/drone/"><i class="fa" aria-hidden="true">drone</i></a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/kernel/"><i class="fa" aria-hidden="true">kernel</i></a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/kubernetes/"><i class="fa" aria-hidden="true">kubernetes</i></a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/kvm/"><i class="fa" aria-hidden="true">kvm</i></a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/mongodb/"><i class="fa" aria-hidden="true">mongodb</i></a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link current" href="/categories/python/"><i class="fa" aria-hidden="true">python</i></a><span class="category-list-count">9</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/share/"><i class="fa" aria-hidden="true">share</i></a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/web/"><i class="fa" aria-hidden="true">web</i></a><span class="category-list-count">12</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/zabbix/"><i class="fa" aria-hidden="true">zabbix</i></a><span class="category-list-count">3</span></li></ul>
</li>


    
    
<li class="widget widget-normal archive">
  <h3 class="fa fa-archive widget-title">归档</h3>
    <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/02/"><i class="fa" aria-hidden="true">二月 2018</i></a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/01/"><i class="fa" aria-hidden="true">一月 2018</i></a><span class="archive-list-count">8</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/12/"><i class="fa" aria-hidden="true">十二月 2017</i></a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/11/"><i class="fa" aria-hidden="true">十一月 2017</i></a><span class="archive-list-count">3</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/10/"><i class="fa" aria-hidden="true">十月 2017</i></a><span class="archive-list-count">4</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/09/"><i class="fa" aria-hidden="true">九月 2017</i></a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/08/"><i class="fa" aria-hidden="true">八月 2017</i></a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/05/"><i class="fa" aria-hidden="true">五月 2017</i></a><span class="archive-list-count">4</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/04/"><i class="fa" aria-hidden="true">四月 2017</i></a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/03/"><i class="fa" aria-hidden="true">三月 2017</i></a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/01/"><i class="fa" aria-hidden="true">一月 2017</i></a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/12/"><i class="fa" aria-hidden="true">十二月 2016</i></a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/11/"><i class="fa" aria-hidden="true">十一月 2016</i></a><span class="archive-list-count">3</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/10/"><i class="fa" aria-hidden="true">十月 2016</i></a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/08/"><i class="fa" aria-hidden="true">八月 2016</i></a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/05/"><i class="fa" aria-hidden="true">五月 2016</i></a><span class="archive-list-count">4</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/04/"><i class="fa" aria-hidden="true">四月 2016</i></a><span class="archive-list-count">8</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/05/"><i class="fa" aria-hidden="true">五月 2015</i></a><span class="archive-list-count">1</span></li></ul>
</li>


    
    
<li class="widget widget-normal tags">
  <h3 class="fa fa-tags widget-title">标签云</h3>
  <div class="tagcloud-content">
    
      <a href="/tags/drone/" style="font-size: 0.14rem; color: #69c">drone</a> <a href="/tags/linux/" style="font-size: 0.2rem; color: #0a407c">linux</a> <a href="/tags/kernel/" style="font-size: 0.16rem; color: #4f83b8">kernel</a> <a href="/tags/ELK/" style="font-size: 0.14rem; color: #69c">ELK</a> <a href="/tags/ansible/" style="font-size: 0.14rem; color: #69c">ansible</a> <a href="/tags/swarm/" style="font-size: 0.14rem; color: #69c">swarm</a> <a href="/tags/docker/" style="font-size: 0.18rem; color: #215690">docker</a> <a href="/tags/firewalld/" style="font-size: 0.14rem; color: #69c">firewalld</a> <a href="/tags/zabbix/" style="font-size: 0.16rem; color: #4f83b8">zabbix</a> <a href="/tags/aws/" style="font-size: 0.14rem; color: #69c">aws</a> <a href="/tags/web/" style="font-size: 0.16rem; color: #4f83b8">web</a> <a href="/tags/python/" style="font-size: 0.18rem; color: #215690">python</a> <a href="/tags/spider/" style="font-size: 0.17rem; color: #386da4">spider</a>
  </div>
</li>


    
    
<li class="widget widget-normal friends-link">
    <h3 class="fa fa-globe widget-title">友链</h3><br/>

    
        <a href="http://zhengwei666.wang" class="fa" target="_blank">zhengwei</a>

    
        <a href="https://you-deng.github.io" class="fa" target="_blank">dengyou</a>

    
        <a href="http://www.systemd.cn" class="fa" target="_blank">langyaoliang</a>

    
        <a href="http://www.chen-hao.com.cn/" class="fa" target="_blank">chenhao</a>

    
        <a href="http://www.yulongjun.com" class="fa" target="_blank">yulongjun</a>

    

</li>

    
</ul>


        <div id="main">
    <article id="post">
        <div id="post-header">

            <h1 id="ansible基础">
                
                ansible基础
                
            </h1>
            <div class="article-meta">
    
    
    <span class="categories-meta fa-wrap">
            <i class="fa fa-folder-open-o"></i>
        <span>ansible</span>
    </span>
    
    
    <span class="fa-wrap">
         <i class="fa fa-tags"></i>
        <span class="tags-meta">
            
            ansible
            
        </span>
    </span>
    
    
    <span class="fa-wrap">
        <i class="fa fa-clock-o"></i>
        <span class="date-meta ">2017/12/02</span>
    </span>
    
    
    <span class="fa-wrap">
            <i class="fa fa-thermometer-three-quarters"></i>
        <span class="hits hits-meta " data-leadcloud-title="ansible基础"
              data-leadcloud-url="/2017/12/02/ansiable/"><i class="fa fa-spinner fa-spin"></i></span>
    </span>
    
    
</div>

            
            
        </div>
        
        <div id="post-body">
            <h1 id="Ansible配置文件"><a href="#Ansible配置文件" class="headerlink" title="Ansible配置文件"></a>Ansible配置文件</h1><h2 id="配置文件说明"><a href="#配置文件说明" class="headerlink" title="配置文件说明"></a>配置文件说明</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div><div class="line">65</div><div class="line">66</div><div class="line">67</div><div class="line">68</div><div class="line">69</div><div class="line">70</div><div class="line">71</div><div class="line">72</div><div class="line">73</div><div class="line">74</div><div class="line">75</div><div class="line">76</div><div class="line">77</div><div class="line">78</div><div class="line">79</div><div class="line">80</div><div class="line">81</div><div class="line">82</div><div class="line">83</div><div class="line">84</div><div class="line">85</div><div class="line">86</div><div class="line">87</div><div class="line">88</div><div class="line">89</div><div class="line">90</div><div class="line">91</div><div class="line">92</div><div class="line">93</div><div class="line">94</div><div class="line">95</div><div class="line">96</div><div class="line">97</div><div class="line">98</div><div class="line">99</div><div class="line">100</div><div class="line">101</div><div class="line">102</div><div class="line">103</div><div class="line">104</div><div class="line">105</div><div class="line">106</div><div class="line">107</div><div class="line">108</div><div class="line">109</div><div class="line">110</div><div class="line">111</div><div class="line">112</div><div class="line">113</div><div class="line">114</div><div class="line">115</div><div class="line">116</div><div class="line">117</div><div class="line">118</div><div class="line">119</div><div class="line">120</div><div class="line">121</div><div class="line">122</div><div class="line">123</div><div class="line">124</div><div class="line">125</div><div class="line">126</div><div class="line">127</div><div class="line">128</div><div class="line">129</div><div class="line">130</div><div class="line">131</div><div class="line">132</div><div class="line">133</div><div class="line">134</div><div class="line">135</div><div class="line">136</div><div class="line">137</div><div class="line">138</div><div class="line">139</div><div class="line">140</div><div class="line">141</div><div class="line">142</div><div class="line">143</div><div class="line">144</div><div class="line">145</div><div class="line">146</div><div class="line">147</div><div class="line">148</div><div class="line">149</div><div class="line">150</div><div class="line">151</div><div class="line">152</div><div class="line">153</div><div class="line">154</div><div class="line">155</div><div class="line">156</div><div class="line">157</div><div class="line">158</div><div class="line">159</div><div class="line">160</div><div class="line">161</div><div class="line">162</div><div class="line">163</div><div class="line">164</div><div class="line">165</div><div class="line">166</div><div class="line">167</div><div class="line">168</div><div class="line">169</div><div class="line">170</div><div class="line">171</div><div class="line">172</div><div class="line">173</div><div class="line">174</div><div class="line">175</div><div class="line">176</div><div class="line">177</div><div class="line">178</div><div class="line">179</div><div class="line">180</div><div class="line">181</div><div class="line">182</div><div class="line">183</div><div class="line">184</div><div class="line">185</div><div class="line">186</div><div class="line">187</div><div class="line">188</div><div class="line">189</div><div class="line">190</div><div class="line">191</div><div class="line">192</div><div class="line">193</div><div class="line">194</div><div class="line">195</div><div class="line">196</div><div class="line">197</div><div class="line">198</div><div class="line">199</div><div class="line">200</div><div class="line">201</div><div class="line">202</div><div class="line">203</div><div class="line">204</div><div class="line">205</div><div class="line">206</div><div class="line">207</div><div class="line">208</div><div class="line">209</div><div class="line">210</div><div class="line">211</div><div class="line">212</div><div class="line">213</div><div class="line">214</div><div class="line">215</div><div class="line">216</div><div class="line">217</div><div class="line">218</div><div class="line">219</div><div class="line">220</div><div class="line">221</div><div class="line">222</div><div class="line">223</div><div class="line">224</div><div class="line">225</div><div class="line">226</div><div class="line">227</div><div class="line">228</div><div class="line">229</div><div class="line">230</div><div class="line">231</div><div class="line">232</div><div class="line">233</div><div class="line">234</div><div class="line">235</div><div class="line">236</div><div class="line">237</div><div class="line">238</div><div class="line">239</div><div class="line">240</div><div class="line">241</div><div class="line">242</div><div class="line">243</div><div class="line">244</div><div class="line">245</div><div class="line">246</div><div class="line">247</div><div class="line">248</div><div class="line">249</div><div class="line">250</div><div class="line">251</div><div class="line">252</div><div class="line">253</div><div class="line">254</div><div class="line">255</div><div class="line">256</div><div class="line">257</div><div class="line">258</div><div class="line">259</div><div class="line">260</div><div class="line">261</div><div class="line">262</div><div class="line">263</div><div class="line">264</div><div class="line">265</div><div class="line">266</div><div class="line">267</div><div class="line">268</div><div class="line">269</div><div class="line">270</div><div class="line">271</div><div class="line">272</div><div class="line">273</div><div class="line">274</div><div class="line">275</div><div class="line">276</div><div class="line">277</div><div class="line">278</div><div class="line">279</div><div class="line">280</div><div class="line">281</div><div class="line">282</div><div class="line">283</div><div class="line">284</div><div class="line">285</div><div class="line">286</div><div class="line">287</div><div class="line">288</div><div class="line">289</div><div class="line">290</div><div class="line">291</div><div class="line">292</div><div class="line">293</div><div class="line">294</div><div class="line">295</div><div class="line">296</div><div class="line">297</div><div class="line">298</div><div class="line">299</div><div class="line">300</div><div class="line">301</div><div class="line">302</div><div class="line">303</div><div class="line">304</div><div class="line">305</div><div class="line">306</div><div class="line">307</div><div class="line">308</div><div class="line">309</div><div class="line">310</div><div class="line">311</div><div class="line">312</div><div class="line">313</div><div class="line">314</div><div class="line">315</div><div class="line">316</div><div class="line">317</div><div class="line">318</div><div class="line">319</div><div class="line">320</div><div class="line">321</div><div class="line">322</div><div class="line">323</div><div class="line">324</div><div class="line">325</div><div class="line">326</div><div class="line">327</div><div class="line">328</div><div class="line">329</div><div class="line">330</div><div class="line">331</div><div class="line">332</div><div class="line">333</div><div class="line">334</div><div class="line">335</div><div class="line">336</div><div class="line">337</div><div class="line">338</div><div class="line">339</div><div class="line">340</div><div class="line">341</div><div class="line">342</div><div class="line">343</div><div class="line">344</div><div class="line">345</div><div class="line">346</div><div class="line">347</div><div class="line">348</div><div class="line">349</div><div class="line">350</div><div class="line">351</div><div class="line">352</div><div class="line">353</div><div class="line">354</div><div class="line">355</div><div class="line">356</div><div class="line">357</div><div class="line">358</div><div class="line">359</div><div class="line">360</div><div class="line">361</div><div class="line">362</div><div class="line">363</div><div class="line">364</div></pre></td><td class="code"><pre><div class="line">Ansible ansible.cfg 配置文件说明</div><div class="line">ansible.cfg</div><div class="line"><span class="comment"># config file for ansible -- http://ansible.com/</span></div><div class="line"><span class="comment"># ==============================================</span></div><div class="line"><span class="comment"># nearly all parameters can be overridden in ansible-playbook</span></div><div class="line"><span class="comment"># or with command line flags. ansible will read ANSIBLE_CONFIG,</span></div><div class="line"><span class="comment"># ansible.cfg in the current working directory, .ansible.cfg in</span></div><div class="line"><span class="comment"># the home directory or /etc/ansible/ansible.cfg, whichever it</span></div><div class="line"><span class="comment"># finds first</span></div><div class="line">[defaults]</div><div class="line"><span class="comment"># some basic default values...</span></div><div class="line"><span class="comment">#inventory      = /etc/ansible/hosts</span></div><div class="line"><span class="comment">#library        = /usr/share/my_modules/</span></div><div class="line"><span class="comment">#remote_tmp     = ~/.ansible/tmp</span></div><div class="line"><span class="comment">#local_tmp      = ~/.ansible/tmp</span></div><div class="line"><span class="comment">#forks          = 5</span></div><div class="line"><span class="comment">#poll_interval  = 15</span></div><div class="line"><span class="comment">#sudo_user      = root</span></div><div class="line"><span class="comment">#ask_sudo_pass = True</span></div><div class="line"><span class="comment">#ask_pass      = True</span></div><div class="line"><span class="comment">#transport      = smart</span></div><div class="line"><span class="comment">#remote_port    = 22</span></div><div class="line"><span class="comment">#module_lang    = C</span></div><div class="line"><span class="comment">#module_set_locale = False</span></div><div class="line"><span class="comment"># plays will gather facts by default, which contain information about</span></div><div class="line"><span class="comment"># the remote system.</span></div><div class="line"><span class="comment">#</span></div><div class="line"><span class="comment"># smart - gather by default, but don't regather if already gathered</span></div><div class="line"><span class="comment"># implicit - gather by default, turn off with gather_facts: False</span></div><div class="line"><span class="comment"># explicit - do not gather by default, must say gather_facts: True</span></div><div class="line"><span class="comment">#gathering = implicit</span></div><div class="line"><span class="comment"># by default retrieve all facts subsets</span></div><div class="line"><span class="comment"># all - gather all subsets</span></div><div class="line"><span class="comment"># network - gather min and network facts</span></div><div class="line"><span class="comment"># hardware - gather hardware facts (longest facts to retrieve)</span></div><div class="line"><span class="comment"># virtual - gather min and virtual facts</span></div><div class="line"><span class="comment"># facter - import facts from facter</span></div><div class="line"><span class="comment"># ohai - import facts from ohai</span></div><div class="line"><span class="comment"># You can combine them using comma (ex: network,virtual)</span></div><div class="line"><span class="comment"># You can negate them using ! (ex: !hardware,!facter,!ohai)</span></div><div class="line"><span class="comment"># A minimal set of facts is always gathered.</span></div><div class="line"><span class="comment">#gather_subset = all</span></div><div class="line"><span class="comment"># some hardware related facts are collected</span></div><div class="line"><span class="comment"># with a maximum timeout of 10 seconds. This</span></div><div class="line"><span class="comment"># option lets you increase or decrease that</span></div><div class="line"><span class="comment"># timeout to something more suitable for the</span></div><div class="line"><span class="comment"># environment.</span></div><div class="line"><span class="comment"># gather_timeout = 10</span></div><div class="line"><span class="comment"># additional paths to search for roles in, colon separated</span></div><div class="line"><span class="comment">#roles_path    = /etc/ansible/roles</span></div><div class="line"><span class="comment"># uncomment this to disable SSH key host checking</span></div><div class="line"><span class="comment">#host_key_checking = False</span></div><div class="line"><span class="comment"># change the default callback</span></div><div class="line"><span class="comment">#stdout_callback = skippy</span></div><div class="line"><span class="comment"># enable additional callbacks</span></div><div class="line"><span class="comment">#callback_whitelist = timer, mail</span></div><div class="line"><span class="comment"># Determine whether includes in tasks and handlers are "static" by</span></div><div class="line"><span class="comment"># default. As of 2.0, includes are dynamic by default. Setting these</span></div><div class="line"><span class="comment"># values to True will make includes behave more like they did in the</span></div><div class="line"><span class="comment"># 1.x versions.</span></div><div class="line"><span class="comment">#task_includes_static = True</span></div><div class="line"><span class="comment">#handler_includes_static = True</span></div><div class="line"><span class="comment"># Controls if a missing handler for a notification event is an error or a warning</span></div><div class="line"><span class="comment">#error_on_missing_handler = True</span></div><div class="line"><span class="comment"># change this for alternative sudo implementations</span></div><div class="line"><span class="comment">#sudo_exe = sudo</span></div><div class="line"><span class="comment"># What flags to pass to sudo</span></div><div class="line"><span class="comment"># WARNING: leaving out the defaults might create unexpected behaviours</span></div><div class="line"><span class="comment">#sudo_flags = -H -S -n</span></div><div class="line"><span class="comment"># SSH timeout</span></div><div class="line"><span class="comment">#timeout = 10</span></div><div class="line"><span class="comment"># default user to use for playbooks if user is not specified</span></div><div class="line"><span class="comment"># (/usr/bin/ansible will use current user as default)</span></div><div class="line"><span class="comment">#remote_user = root</span></div><div class="line"><span class="comment"># logging is off by default unless this path is defined</span></div><div class="line"><span class="comment"># if so defined, consider logrotate</span></div><div class="line"><span class="comment">#log_path = /var/log/ansible.log</span></div><div class="line"><span class="comment"># default module name for /usr/bin/ansible</span></div><div class="line"><span class="comment">#module_name = command</span></div><div class="line"><span class="comment"># use this shell for commands executed under sudo</span></div><div class="line"><span class="comment"># you may need to change this to bin/bash in rare instances</span></div><div class="line"><span class="comment"># if sudo is constrained</span></div><div class="line"><span class="comment">#executable = /bin/sh</span></div><div class="line"><span class="comment"># if inventory variables overlap, does the higher precedence one win</span></div><div class="line"><span class="comment"># or are hash values merged together?  The default is 'replace' but</span></div><div class="line"><span class="comment"># this can also be set to 'merge'.</span></div><div class="line"><span class="comment">#hash_behaviour = replace</span></div><div class="line"><span class="comment"># by default, variables from roles will be visible in the global variable</span></div><div class="line"><span class="comment"># scope. To prevent this, the following option can be enabled, and only</span></div><div class="line"><span class="comment"># tasks and handlers within the role will see the variables there</span></div><div class="line"><span class="comment">#private_role_vars = yes</span></div><div class="line"><span class="comment"># list any Jinja2 extensions to enable here:</span></div><div class="line"><span class="comment">#jinja2_extensions = jinja2.ext.do,jinja2.ext.i18n</span></div><div class="line"><span class="comment"># if set, always use this private key file for authentication, same as</span></div><div class="line"><span class="comment"># if passing --private-key to ansible or ansible-playbook</span></div><div class="line"><span class="comment">#private_key_file = /path/to/file</span></div><div class="line"><span class="comment"># If set, configures the path to the Vault password file as an alternative to</span></div><div class="line"><span class="comment"># specifying --vault-password-file on the command line.</span></div><div class="line"><span class="comment">#vault_password_file = /path/to/vault_password_file</span></div><div class="line"><span class="comment"># format of string &#123;&#123; ansible_managed &#125;&#125; available within Jinja2</span></div><div class="line"><span class="comment"># templates indicates to users editing templates files will be replaced.</span></div><div class="line"><span class="comment"># replacing &#123;file&#125;, &#123;host&#125; and &#123;uid&#125; and strftime codes with proper values.</span></div><div class="line"><span class="comment">#ansible_managed = Ansible managed: &#123;file&#125; modified on %Y-%m-%d %H:%M:%S by &#123;uid&#125; on &#123;host&#125;</span></div><div class="line"><span class="comment"># &#123;file&#125;, &#123;host&#125;, &#123;uid&#125;, and the timestamp can all interfere with idempotence</span></div><div class="line"><span class="comment"># in some situations so the default is a static string:</span></div><div class="line"><span class="comment">#ansible_managed = Ansible managed</span></div><div class="line"><span class="comment"># by default, ansible-playbook will display "Skipping [host]" if it determines a task</span></div><div class="line"><span class="comment"># should not be run on a host.  Set this to "False" if you don't want to see these "Skipping"</span></div><div class="line"><span class="comment"># messages. <span class="doctag">NOTE:</span> the task header will still be shown regardless of whether or not the</span></div><div class="line"><span class="comment"># task is skipped.</span></div><div class="line"><span class="comment">#display_skipped_hosts = True</span></div><div class="line"><span class="comment"># by default, if a task in a playbook does not include a name: field then</span></div><div class="line"><span class="comment"># ansible-playbook will construct a header that includes the task's action but</span></div><div class="line"><span class="comment"># not the task's args.  This is a security feature because ansible cannot know</span></div><div class="line"><span class="comment"># if the *module* considers an argument to be no_log at the time that the</span></div><div class="line"><span class="comment"># header is printed.  If your environment doesn't have a problem securing</span></div><div class="line"><span class="comment"># stdout from ansible-playbook (or you have manually specified no_log in your</span></div><div class="line"><span class="comment"># playbook on all of the tasks where you have secret information) then you can</span></div><div class="line"><span class="comment"># safely set this to True to get more informative messages.</span></div><div class="line"><span class="comment">#display_args_to_stdout = False</span></div><div class="line"><span class="comment"># by default (as of 1.3), Ansible will raise errors when attempting to dereference</span></div><div class="line"><span class="comment"># Jinja2 variables that are not set in templates or action lines. Uncomment this line</span></div><div class="line"><span class="comment"># to revert the behavior to pre-1.3.</span></div><div class="line"><span class="comment">#error_on_undefined_vars = False</span></div><div class="line"><span class="comment"># by default (as of 1.6), Ansible may display warnings based on the configuration of the</span></div><div class="line"><span class="comment"># system running ansible itself. This may include warnings about 3rd party packages or</span></div><div class="line"><span class="comment"># other conditions that should be resolved if possible.</span></div><div class="line"><span class="comment"># to disable these warnings, set the following value to False:</span></div><div class="line"><span class="comment">#system_warnings = True</span></div><div class="line"><span class="comment"># by default (as of 1.4), Ansible may display deprecation warnings for language</span></div><div class="line"><span class="comment"># features that should no longer be used and will be removed in future versions.</span></div><div class="line"><span class="comment"># to disable these warnings, set the following value to False:</span></div><div class="line"><span class="comment">#deprecation_warnings = True</span></div><div class="line"><span class="comment"># (as of 1.8), Ansible can optionally warn when usage of the shell and</span></div><div class="line"><span class="comment"># command module appear to be simplified by using a default Ansible module</span></div><div class="line"><span class="comment"># instead.  These warnings can be silenced by adjusting the following</span></div><div class="line"><span class="comment"># setting or adding warn=yes or warn=no to the end of the command line</span></div><div class="line"><span class="comment"># parameter string.  This will for example suggest using the git module</span></div><div class="line"><span class="comment"># instead of shelling out to the git command.</span></div><div class="line"><span class="comment"># command_warnings = False</span></div><div class="line"><span class="comment"># set plugin path directories here, separate with colons</span></div><div class="line"><span class="comment">#action_plugins     = /usr/share/ansible/plugins/action</span></div><div class="line"><span class="comment">#cache_plugins      = /usr/share/ansible/plugins/cache</span></div><div class="line"><span class="comment">#callback_plugins   = /usr/share/ansible/plugins/callback</span></div><div class="line"><span class="comment">#connection_plugins = /usr/share/ansible/plugins/connection</span></div><div class="line"><span class="comment">#lookup_plugins     = /usr/share/ansible/plugins/lookup</span></div><div class="line"><span class="comment">#inventory_plugins  = /usr/share/ansible/plugins/inventory</span></div><div class="line"><span class="comment">#vars_plugins       = /usr/share/ansible/plugins/vars</span></div><div class="line"><span class="comment">#filter_plugins     = /usr/share/ansible/plugins/filter</span></div><div class="line"><span class="comment">#test_plugins       = /usr/share/ansible/plugins/test</span></div><div class="line"><span class="comment">#strategy_plugins   = /usr/share/ansible/plugins/strategy</span></div><div class="line"><span class="comment"># by default callbacks are not loaded for /bin/ansible, enable this if you</span></div><div class="line"><span class="comment"># want, for example, a notification or logging callback to also apply to</span></div><div class="line"><span class="comment"># /bin/ansible runs</span></div><div class="line"><span class="comment">#bin_ansible_callbacks = False</span></div><div class="line"><span class="comment"># don't like cows?  that's unfortunate.</span></div><div class="line"><span class="comment"># set to 1 if you don't want cowsay support or export ANSIBLE_NOCOWS=1</span></div><div class="line"><span class="comment">#nocows = 1</span></div><div class="line"><span class="comment"># set which cowsay stencil you'd like to use by default. When set to 'random',</span></div><div class="line"><span class="comment"># a random stencil will be selected for each task. The selection will be filtered</span></div><div class="line"><span class="comment"># against the `cow_whitelist` option below.</span></div><div class="line"><span class="comment">#cow_selection = default</span></div><div class="line"><span class="comment">#cow_selection = random</span></div><div class="line"><span class="comment"># when using the 'random' option for cowsay, stencils will be restricted to this list.</span></div><div class="line"><span class="comment"># it should be formatted as a comma-separated list with no spaces between names.</span></div><div class="line"><span class="comment"># <span class="doctag">NOTE:</span> line continuations here are for formatting purposes only, as the INI parser</span></div><div class="line"><span class="comment">#       in python does not support them.</span></div><div class="line"><span class="comment">#cow_whitelist=bud-frogs,bunny,cheese,daemon,default,dragon,elephant-in-snake,elephant,eyes,\</span></div><div class="line"><span class="comment">#              hellokitty,kitty,luke-koala,meow,milk,moofasa,moose,ren,sheep,small,stegosaurus,\</span></div><div class="line"><span class="comment">#              stimpy,supermilker,three-eyes,turkey,turtle,tux,udder,vader-koala,vader,www</span></div><div class="line"><span class="comment"># don't like colors either?</span></div><div class="line"><span class="comment"># set to 1 if you don't want colors, or export ANSIBLE_NOCOLOR=1</span></div><div class="line"><span class="comment">#nocolor = 1</span></div><div class="line"><span class="comment"># if set to a persistent type (not 'memory', for example 'redis') fact values</span></div><div class="line"><span class="comment"># from previous runs in Ansible will be stored.  This may be useful when</span></div><div class="line"><span class="comment"># wanting to use, for example, IP information from one group of servers</span></div><div class="line"><span class="comment"># without having to talk to them in the same playbook run to get their</span></div><div class="line"><span class="comment"># current IP information.</span></div><div class="line"><span class="comment">#fact_caching = memory</span></div><div class="line"><span class="comment"># retry files</span></div><div class="line"><span class="comment"># When a playbook fails by default a .retry file will be created in ~/</span></div><div class="line"><span class="comment"># You can disable this feature by setting retry_files_enabled to False</span></div><div class="line"><span class="comment"># and you can change the location of the files by setting retry_files_save_path</span></div><div class="line"><span class="comment">#retry_files_enabled = False</span></div><div class="line"><span class="comment">#retry_files_save_path = ~/.ansible-retry</span></div><div class="line"><span class="comment"># squash actions</span></div><div class="line"><span class="comment"># Ansible can optimise actions that call modules with list parameters</span></div><div class="line"><span class="comment"># when looping. Instead of calling the module once per with_ item, the</span></div><div class="line"><span class="comment"># module is called once with all items at once. Currently this only works</span></div><div class="line"><span class="comment"># under limited circumstances, and only with parameters named 'name'.</span></div><div class="line"><span class="comment">#squash_actions = apk,apt,dnf,homebrew,package,pacman,pkgng,yum,zypper</span></div><div class="line"><span class="comment"># prevents logging of task data, off by default</span></div><div class="line"><span class="comment">#no_log = False</span></div><div class="line"><span class="comment"># prevents logging of tasks, but only on the targets, data is still logged on the master/controller</span></div><div class="line"><span class="comment">#no_target_syslog = False</span></div><div class="line"><span class="comment"># controls whether Ansible will raise an error or warning if a task has no</span></div><div class="line"><span class="comment"># choice but to create world readable temporary files to execute a module on</span></div><div class="line"><span class="comment"># the remote machine.  This option is False by default for security.  Users may</span></div><div class="line"><span class="comment"># turn this on to have behaviour more like Ansible prior to 2.1.x.  See</span></div><div class="line"><span class="comment"># https://docs.ansible.com/ansible/become.html#becoming-an-unprivileged-user</span></div><div class="line"><span class="comment"># for more secure ways to fix this than enabling this option.</span></div><div class="line"><span class="comment">#allow_world_readable_tmpfiles = False</span></div><div class="line"><span class="comment"># controls the compression level of variables sent to</span></div><div class="line"><span class="comment"># worker processes. At the default of 0, no compression</span></div><div class="line"><span class="comment"># is used. This value must be an integer from 0 to 9.</span></div><div class="line"><span class="comment">#var_compression_level = 9</span></div><div class="line"><span class="comment"># controls what compression method is used for new-style ansible modules when</span></div><div class="line"><span class="comment"># they are sent to the remote system.  The compression types depend on having</span></div><div class="line"><span class="comment"># support compiled into both the controller's python and the client's python.</span></div><div class="line"><span class="comment"># The names should match with the python Zipfile compression types:</span></div><div class="line"><span class="comment"># * ZIP_STORED (no compression. available everywhere)</span></div><div class="line"><span class="comment"># * ZIP_DEFLATED (uses zlib, the default)</span></div><div class="line"><span class="comment"># These values may be set per host via the ansible_module_compression inventory</span></div><div class="line"><span class="comment"># variable</span></div><div class="line"><span class="comment">#module_compression = 'ZIP_DEFLATED'</span></div><div class="line"><span class="comment"># This controls the cutoff point (in bytes) on --diff for files</span></div><div class="line"><span class="comment"># set to 0 for unlimited (RAM may suffer!).</span></div><div class="line"><span class="comment">#max_diff_size = 1048576</span></div><div class="line">[privilege_escalation]</div><div class="line"><span class="comment">#become=True</span></div><div class="line"><span class="comment">#become_method=sudo</span></div><div class="line"><span class="comment">#become_user=root</span></div><div class="line"><span class="comment">#become_ask_pass=False</span></div><div class="line">[paramiko_connection]</div><div class="line"><span class="comment"># uncomment this line to cause the paramiko connection plugin to not record new host</span></div><div class="line"><span class="comment"># keys encountered.  Increases performance on new host additions.  Setting works independently of the</span></div><div class="line"><span class="comment"># host key checking setting above.</span></div><div class="line"><span class="comment">#record_host_keys=False</span></div><div class="line"><span class="comment"># by default, Ansible requests a pseudo-terminal for commands executed under sudo. Uncomment this</span></div><div class="line"><span class="comment"># line to disable this behaviour.</span></div><div class="line"><span class="comment">#pty=False</span></div><div class="line">[ssh_connection]</div><div class="line"><span class="comment"># ssh arguments to use</span></div><div class="line"><span class="comment"># Leaving off ControlPersist will result in poor performance, so use</span></div><div class="line"><span class="comment"># paramiko on older platforms rather than removing it, -C controls compression use</span></div><div class="line"><span class="comment">#ssh_args = -C -o ControlMaster=auto -o ControlPersist=60s</span></div><div class="line"><span class="comment"># The path to use for the ControlPath sockets. This defaults to</span></div><div class="line"><span class="comment"># "%(directory)s/ansible-ssh-%%h-%%p-%%r", however on some systems with</span></div><div class="line"><span class="comment"># very long hostnames or very long path names (caused by long user names or</span></div><div class="line"><span class="comment"># deeply nested home directories) this can exceed the character limit on</span></div><div class="line"><span class="comment"># file socket names (108 characters for most platforms). In that case, you</span></div><div class="line"><span class="comment"># may wish to shorten the string below.</span></div><div class="line"><span class="comment">#</span></div><div class="line"><span class="comment"># Example:</span></div><div class="line"><span class="comment"># control_path = %(directory)s/%%h-%%r</span></div><div class="line"><span class="comment">#control_path = %(directory)s/ansible-ssh-%%h-%%p-%%r</span></div><div class="line"><span class="comment"># Enabling pipelining reduces the number of SSH operations required to</span></div><div class="line"><span class="comment"># execute a module on the remote server. This can result in a significant</span></div><div class="line"><span class="comment"># performance improvement when enabled, however when using "sudo:" you must</span></div><div class="line"><span class="comment"># first disable 'requiretty' in /etc/sudoers</span></div><div class="line"><span class="comment">#</span></div><div class="line"><span class="comment"># By default, this option is disabled to preserve compatibility with</span></div><div class="line"><span class="comment"># sudoers configurations that have requiretty (the default on many distros).</span></div><div class="line"><span class="comment">#</span></div><div class="line"><span class="comment">#pipelining = False</span></div><div class="line"><span class="comment"># Control the mechanism for transfering files</span></div><div class="line"><span class="comment">#   * smart = try sftp and then try scp [default]</span></div><div class="line"><span class="comment">#   * True = use scp only</span></div><div class="line"><span class="comment">#   * False = use sftp only</span></div><div class="line"><span class="comment">#scp_if_ssh = smart</span></div><div class="line"><span class="comment"># if False, sftp will not use batch mode to transfer files. This may cause some</span></div><div class="line"><span class="comment"># types of file transfer failures impossible to catch however, and should</span></div><div class="line"><span class="comment"># only be disabled if your sftp version has problems with batch mode</span></div><div class="line"><span class="comment">#sftp_batch_mode = False</span></div><div class="line">[accelerate]</div><div class="line"><span class="comment">#accelerate_port = 5099</span></div><div class="line"><span class="comment">#accelerate_timeout = 30</span></div><div class="line"><span class="comment">#accelerate_connect_timeout = 5.0</span></div><div class="line"><span class="comment"># The daemon timeout is measured in minutes. This time is measured</span></div><div class="line"><span class="comment"># from the last activity to the accelerate daemon.</span></div><div class="line"><span class="comment">#accelerate_daemon_timeout = 30</span></div><div class="line"><span class="comment"># If set to yes, accelerate_multi_key will allow multiple</span></div><div class="line"><span class="comment"># private keys to be uploaded to it, though each user must</span></div><div class="line"><span class="comment"># have access to the system via SSH to add a new key. The default</span></div><div class="line"><span class="comment"># is "no".</span></div><div class="line"><span class="comment">#accelerate_multi_key = yes</span></div><div class="line">[selinux]</div><div class="line"><span class="comment"># file systems that require special treatment when dealing with security context</span></div><div class="line"><span class="comment"># the default behaviour that copies the existing context or uses the user default</span></div><div class="line"><span class="comment"># needs to be changed to use the file system dependent context.</span></div><div class="line"><span class="comment">#special_context_filesystems=nfs,vboxsf,fuse,ramfs</span></div><div class="line"><span class="comment"># Set this to yes to allow libvirt_lxc connections to work without SELinux.</span></div><div class="line"><span class="comment">#libvirt_lxc_noseclabel = yes</span></div><div class="line">[colors]</div><div class="line"><span class="comment">#highlight = white</span></div><div class="line"><span class="comment">#verbose = blue</span></div><div class="line"><span class="comment">#warn = bright purple</span></div><div class="line"><span class="comment">#error = red</span></div><div class="line"><span class="comment">#debug = dark gray</span></div><div class="line"><span class="comment">#deprecate = purple</span></div><div class="line"><span class="comment">#skip = cyan</span></div><div class="line"><span class="comment">#unreachable = red</span></div><div class="line"><span class="comment">#ok = green</span></div><div class="line"><span class="comment">#changed = yellow</span></div><div class="line"><span class="comment">#diff_add = green</span></div><div class="line"><span class="comment">#diff_remove = red</span></div><div class="line"><span class="comment">#diff_lines = cyan</span></div></pre></td></tr></table></figure>
<p>说明：</p>
<blockquote>
<p>inventory：表示清单 inventory 文件的位置，资源清单就是 Ansible 需要连接管理的主机列表。<br>library：Ansible 的操作动作，无论是本地或是远程，都是使用一小段代码来执行，这小段代码称为模块,  library 存放 Ansible 模块的目录。<br>forks：默认情况下 Ansible 最多能有多少个进程同时工作，默认设置 5 个进程并行处理。<br>sudo_user：默认执行命令的用户。<br>remote_port：连接管理端口，默认 22。<br>host_key_checking：这里设置是否检查 SSH 主机的秘钥，可以设置为 True 或者 False。<br>timeout：SSH 连接的超市间隔，默认是秒。<br>log_path：Ansible 系统默认的是不记录日志的，可以把日志输入到文件内。</p>
</blockquote>
<h2 id="ansible-hosts"><a href="#ansible-hosts" class="headerlink" title="ansible_hosts"></a>ansible_hosts</h2><p>配置文件默认在/etc/ansible/hosts<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div></pre></td><td class="code"><pre><div class="line"><span class="comment"># This is the default ansible 'hosts' file.</span></div><div class="line"><span class="comment">#</span></div><div class="line"><span class="comment"># It should live in /etc/ansible/hosts</span></div><div class="line"><span class="comment">#</span></div><div class="line"><span class="comment">#   - Comments begin with the '#' character</span></div><div class="line"><span class="comment">#   - Blank lines are ignored</span></div><div class="line"><span class="comment">#   - Groups of hosts are delimited by [header] elements</span></div><div class="line"><span class="comment">#   - You can enter hostnames or ip addresses</span></div><div class="line"><span class="comment">#   - A hostname/ip can be a member of multiple groups</span></div><div class="line"><span class="comment"># Ex 1: Ungrouped hosts, specify before any group headers.</span></div><div class="line"><span class="comment">## green.example.com</span></div><div class="line"><span class="comment">## blue.example.com</span></div><div class="line"><span class="comment">## 192.168.100.1</span></div><div class="line"><span class="comment">## 192.168.100.10</span></div><div class="line"><span class="comment"># Ex 2: A collection of hosts belonging to the 'webservers' group</span></div><div class="line"><span class="comment">## [webservers]</span></div><div class="line"><span class="comment">## alpha.example.org</span></div><div class="line"><span class="comment">## beta.example.org</span></div><div class="line"><span class="comment">## 192.168.1.100</span></div><div class="line"><span class="comment">## 192.168.1.110</span></div><div class="line"><span class="comment"># If you have multiple hosts following a pattern you can specify</span></div><div class="line"><span class="comment"># them like this:</span></div><div class="line"><span class="comment">## www[001:006].example.com</span></div><div class="line"><span class="comment"># Ex 3: A collection of database servers in the 'dbservers' group</span></div><div class="line"><span class="comment">## [dbservers]</span></div><div class="line"><span class="comment">##</span></div><div class="line"><span class="comment">## db01.intranet.mydomain.net</span></div><div class="line"><span class="comment">## db02.intranet.mydomain.net</span></div><div class="line"><span class="comment">## 10.25.1.56</span></div><div class="line"><span class="comment">## 10.25.1.57</span></div><div class="line"><span class="comment"># Here's another example of host ranges, this time there are no</span></div><div class="line"><span class="comment"># leading 0s:</span></div><div class="line"><span class="comment">## db-[99:101]-node.example.com</span></div></pre></td></tr></table></figure></p>
<p>说明：</p>
<ul>
<li>中括号 “[ ]” 表示一组节点的名称，如 : [web] , 这样 web 下的所以节点只需要对 web 执行命令即可。<br>example:</li>
<li><p>添加一个web节点：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">[web]</div><div class="line">192.168.2.250</div></pre></td></tr></table></figure>
</li>
<li><p>执行命令:</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line">$ ansible docker -m ping</div><div class="line">192.168.2.250 | SUCCESS =&gt; &#123;</div><div class="line">    <span class="string">"changed"</span>: <span class="literal">false</span>, </div><div class="line">    <span class="string">"failed"</span>: <span class="literal">false</span>, </div><div class="line">    <span class="string">"ping"</span>: <span class="string">"pong"</span></div><div class="line">&#125;</div></pre></td></tr></table></figure>
</li>
</ul>
<h3 id="定义ansible-hosts"><a href="#定义ansible-hosts" class="headerlink" title="定义ansible hosts"></a>定义ansible hosts</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">vim /etc/ansible/hosts</div><div class="line">[web]</div><div class="line">127.0.0.1</div><div class="line">192.168.2.250</div><div class="line"><span class="comment">#定义的ip服务器 都需要把公钥copy过去，如果定义的是hostname，需要在系统的hosts配置文件里面写好</span></div></pre></td></tr></table></figure>
<p>简单测试<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">ansible web -m <span class="built_in">command</span> -a <span class="string">'w'</span></div><div class="line">ansible web -m shell -a <span class="string">'w'</span></div></pre></td></tr></table></figure></p>
<p><strong>-m</strong>定义要使用模块的名字<br><strong>-a</strong>定义要运行的命令<br><strong>shell</strong>模块支持sh命令下的管道输入，管道命令用command会报错</p>
<h2 id="copy文件与目录"><a href="#copy文件与目录" class="headerlink" title="copy文件与目录"></a>copy文件与目录</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">ansible web -m copy -a <span class="string">"src=/etc/passwd  dest=/tmp/password.txt owner=root group=root mode=755"</span></div><div class="line">ansible web -m copy -a <span class="string">"src=/var/log/apt  dest=/tmp"</span></div></pre></td></tr></table></figure>
<p>这里使用<strong>COPY</strong>模块,SRT是本地路径，DEST是远程目录，OWNER是文件属主，GROUP是文件属组，MODE是文件权限，文件属主属组权限也可不写。</p>
<h2 id="计划任务"><a href="#计划任务" class="headerlink" title="计划任务"></a>计划任务</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">ansible web -m cron -a <span class="string">"name=test_name job='/bin/bash /usr/local/src/1.sh' minute=1-10 day=1,4,7,10 weekday=5"</span></div><div class="line">ansible web -m cron -a <span class="string">"name=test_name state=absent"</span></div></pre></td></tr></table></figure>
<p>这里的<strong>CRON</strong>是模块，TEST_NAME是指定任务名称方便以后删除，JOB是具体的执行命令，WEEKDAY是在制定在周五去执行，分钟是MINUTE，小时是HOUR，日期是DAY，月份是MOUTH。<br>删除是固定语句state=absent。</p>
<h2 id="安装模块"><a href="#安装模块" class="headerlink" title="安装模块"></a>安装模块</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line">ansible web -m yum -a <span class="string">"name=ntp state=present"</span>  <span class="comment">#安装</span></div><div class="line">ansible web -m yum -a <span class="string">"name=ntp state=absent"</span>   <span class="comment">#删除</span></div><div class="line">ansible web -m apt -a <span class="string">"name=nginx state=present"</span>  <span class="comment">#安装</span></div><div class="line">ansible web -m apt -a <span class="string">"name=nginx state=absent"</span>   <span class="comment">#删除</span></div></pre></td></tr></table></figure>
<h2 id="服务开机启动"><a href="#服务开机启动" class="headerlink" title="服务开机启动"></a>服务开机启动</h2><h2 id="收集主机信息"><a href="#收集主机信息" class="headerlink" title="收集主机信息"></a>收集主机信息</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">ansible web -m setup</div></pre></td></tr></table></figure>
<h2 id="异步执行，返回每个jobs的ID"><a href="#异步执行，返回每个jobs的ID" class="headerlink" title="异步执行，返回每个jobs的ID"></a>异步执行，返回每个jobs的ID</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div></pre></td><td class="code"><pre><div class="line">ansible docker -B 120 -P 0 -m ping</div><div class="line">192.168.2.250 | SUCCESS =&gt; &#123;</div><div class="line">    <span class="string">"ansible_job_id"</span>: <span class="string">"560759915248.10453"</span>, </div><div class="line">    <span class="string">"changed"</span>: <span class="literal">true</span>, </div><div class="line">    <span class="string">"failed"</span>: <span class="literal">false</span>, </div><div class="line">    <span class="string">"finished"</span>: 0, </div><div class="line">    <span class="string">"results_file"</span>: <span class="string">"/root/.ansible_async/560759915248.10453"</span>, </div><div class="line">    <span class="string">"started"</span>: 1</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>每台主机会产生不同的 <strong>job_id</strong>，可以通过 <strong>async_status</strong> 模块查看异步任务的状态与结果：<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">$ ansible docker -m async_status -a <span class="string">'jid=560759915248.10453'</span></div></pre></td></tr></table></figure></p>
<h2 id="Inventory-内置参数"><a href="#Inventory-内置参数" class="headerlink" title="Inventory 内置参数"></a>Inventory 内置参数</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div></pre></td><td class="code"><pre><div class="line">ansible_ssh_host</div><div class="line">      将要连接的远程主机名.与你想要设定的主机的别名不同的话,可通过此变量设置.</div><div class="line">ansible_ssh_port</div><div class="line">      ssh端口号.如果不是默认的端口号,通过此变量设置.</div><div class="line">ansible_ssh_user</div><div class="line">      默认的 ssh 用户名</div><div class="line">ansible_ssh_pass</div><div class="line">      ssh 密码(这种方式并不安全,我们强烈建议使用 --ask-pass 或 SSH 密钥)</div><div class="line">ansible_sudo_pass</div><div class="line">      sudo 密码(这种方式并不安全,我们强烈建议使用 --ask-sudo-pass)</div><div class="line">ansible_sudo_exe (new <span class="keyword">in</span> version 1.8)</div><div class="line">      sudo 命令路径(适用于1.8及以上版本)</div><div class="line">ansible_connection</div><div class="line">      与主机的连接类型.比如:<span class="built_in">local</span>, ssh 或者 paramiko. Ansible 1.2 以前默认使用 paramiko.1.2 以后默认使用 <span class="string">'smart'</span>,<span class="string">'smart'</span> 方式会根据是否支持 ControlPersist, 来判断<span class="string">'ssh'</span> 方式是否可行.</div><div class="line">ansible_ssh_private_key_file</div><div class="line">      ssh 使用的私钥文件.适用于有多个密钥,而你不想使用 SSH 代理的情况.</div><div class="line">ansible_shell_type</div><div class="line">      目标系统的shell类型.默认情况下,命令的执行使用 <span class="string">'sh'</span> 语法,可设置为 <span class="string">'csh'</span> 或 <span class="string">'fish'</span>.</div><div class="line">ansible_python_interpreter</div><div class="line">      目标主机的 python 路径.适用于的情况: 系统中有多个 Python, 或者命令路径不是<span class="string">"/usr/bin/python"</span>,比如  \*BSD, 或者 /usr/bin/python</div><div class="line">      不是 2.X 版本的 Python.我们不使用 <span class="string">"/usr/bin/env"</span> 机制,因为这要求远程用户的路径设置正确,且要求 <span class="string">"python"</span> 可执行程序名不可为 python以外的名字(实际有可能名为python26).</div><div class="line">      与 ansible_python_interpreter 的工作方式相同,可设定如 ruby 或 perl 的路径....</div></pre></td></tr></table></figure>

        </div>
        <div id="post-footer">
            <div class="avatar" >
                <img src="/img/author.jpg" alt="avatar"/>
                <!-- 
                <a href="javascript:void(0)" class="high-song">high起来 &#128541;</a>
                 -->
                
                <a href="http://backup-miabon.oss-cn-hongkong.aliyuncs.com/img/alipay.jpg" target="_blank" class="donate fa">打赏小弟 &#128536;</a>
                
            </div>
            <ul class="author-profile-section">
                <li>
                  
                  作者:
                  
                    
                    <a href="/about.html">MIAbon</a>
                </li>
                
                <li>发表日期: <span>2017-12-02  00:00:00</span></li>
                
                <li>最后编辑日期: <span>2017-12-19  20:44:58</span></li>
                
                <li class="post-category">
                    文章分类:
                    
                    <a href="/categories/ansible/">ansible</a>
                    
                </li>
                <li class="post-tags">
                    文章标签:
                    
                    <a href="/tags/ansible/">ansible</a>
                    
                </li>
                
                <li> 版权声明: <a href="https://creativecommons.org/licenses/by-nc-nd/3.0/" target="_blank">
知识共享署名-非商业性使用-禁止演绎 3.0 未本地化版本许可协议（CC BY-NC-ND 3.0）
</a></li>
                
            </ul>
            <div id="donate-wrap">
                
                
                
                <img src="http://www.geasslinks.com/img/alipay.jpg" alt="支付宝付款" class="donate-img">
                
                
            </div>
        </div>
    </article>
    <div class="article-nav">
        
        <a href="/2018/01/01/maoyan_top100/" class="pre-post fa fa-caret-left">简单爬虫猫眼TOP100</a>
        
        
        <a href="/2017/11/29/Linux升级内核开启BBR的好处/" class="next-post fa">Linux升级内核开启BBR的好处</a>
        
    </div>
    
    <div id="comments">
        

<script>
  gitment.render(document.getElementById("comments"));
</script>



    </div>
    
</div>


    </div>
    <footer id="footer">
    
    <div class="social">
        
        <a href="https://www.example1.com" class="fa fa-free-code-camp" target="_blank" title="freecodecamp"></a>
        
        <a href="https://github.com/werewolf2101" class="fa fa-github" target="_blank" title="Follow me~"></a>
        
        <a href="mailto:werewolf2101@gmail.com" class="fa fa-email" target="_blank" title="Email"></a>
        
    </div>
    
    <div>
        
        <a href="/" class="copyright-links">MIAbon</a>&copy;2015 - 2018.All Rights
        Reserved.
    </div>
    <p>Powered by <a href="https://hexo.io" class="copyright-links" target="_blank">Hexo</a> | Theme by <a
                href="https://github.com/GeekaholicLin" class="copyright-links" target="_blank">GeekaholicLin</a>
    </p>
    
    
    <p>
        <span id="busuanzi_container_site_uv" class="fa fa-bar-chart">
        欢迎第<span id="busuanzi_value_site_uv"><i class="fa fa-spinner fa-spin"></i></span>位小伙伴~
        </span>
    </p>
    
</footer>

</div>
    <ul id="tools">
    <li class="totop-btn fa fa-angle-up"></li>
    <li class="exchange-btn fa fa-exchange"></li>
  
    <li class="toc-btn fa fa-list-ul"></li>
    
    

    
</ul>
<p id="process"></p>
<div id="search-overlay">
    <div class="search-area-wrap">
        <div id="search-area">
            <div class="input-wrap focus">
                <i class="fa fa-search" aria-hidden="true"></i>
                <input id="search-input" autofocus autocomplete="off" type="text"
                       placeholder="search this website..."/>
            </div>
            <ul id="search-result">
                <li class="load-first"><i class="fa fa-spinner fa-pulse"></i></li>
            </ul>
        </div>
    </div>
</div>

    <ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#Ansible配置文件"><span class="toc-number">1.</span> <span class="toc-text">Ansible配置文件</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#配置文件说明"><span class="toc-number">1.1.</span> <span class="toc-text">配置文件说明</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#ansible-hosts"><span class="toc-number">1.2.</span> <span class="toc-text">ansible_hosts</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#定义ansible-hosts"><span class="toc-number">1.2.1.</span> <span class="toc-text">定义ansible hosts</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#copy文件与目录"><span class="toc-number">1.3.</span> <span class="toc-text">copy文件与目录</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#计划任务"><span class="toc-number">1.4.</span> <span class="toc-text">计划任务</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#安装模块"><span class="toc-number">1.5.</span> <span class="toc-text">安装模块</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#服务开机启动"><span class="toc-number">1.6.</span> <span class="toc-text">服务开机启动</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#收集主机信息"><span class="toc-number">1.7.</span> <span class="toc-text">收集主机信息</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#异步执行，返回每个jobs的ID"><span class="toc-number">1.8.</span> <span class="toc-text">异步执行，返回每个jobs的ID</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Inventory-内置参数"><span class="toc-number">1.9.</span> <span class="toc-text">Inventory 内置参数</span></a></li></ol></li></ol>


    <script src="/js/highsong.js"></script>



<script src="/js/search.js"></script>
<script type="text/javascript">
    //theme config datas
    var copyrightObj = {};
    copyrightObj.enable = 'true';
    copyrightObj.triggerCopyLength = '200';
    copyrightObj.appendText = '商业转载请联系作者获得授权,非商业转载请注明出处 © gasslinks.com';
    var leancloudObj = {};
    leancloudObj.enable = 'true';
    leancloudObj.className = 'blog';
    leancloudObj.limits = '5';
</script>
<script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?dfebe5842f5d4196471b84802392a4b2";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script>
<script type="text/javascript">
    var search = {};
    var search_path = "search.xml";
    if (!search_path) {
        search_path = "search.xml";
    }
    search.path = "/" + search_path;
    search.func =  _ajax.init();
</script>
<script src="/js/app.js"></script>


</body>
</html>